#pragma once
#include "MyNode.h"
#include "MyLinearList.h"
#include "MyExtendedLinearList.h"
template <typename T>
class myExtendedChainList : public myExtendedLinearList<T> {
public:
	myExtendedChainList();
	~myExtendedLChainList();
	myExtendedChainList(const myExtendedChainList<T>& chain);

	bool empty() const { return size == 0; }
	int get_size() const { return size; }
	T& get_element(int index) const;
	int index_of(const T& _element) const;
	void insert(const T& _element, int index);
	void erase(int index);
	void output(std::ostream& os = cout) const;
	void clear();
	void push_back(const T& _element);
protected:
	myChainNode<T>* firstNode;
	myChainNode<T>* lastNode;
	int size;

	void check_index(int index) const;
};

template <typename T>
myExtendedChainList<T>::myExtendedChainList() {
	firstNode = lastNode = nullptr;
	size = 0;
}
template <typename T>
myExtendedChainList<T>::myExtendedChainList(const myExtendedChainList<T>& chain) {
	size = chain.get_size();
	if (chain.get_size() == 0) {
		firstNode = lastNode = nullptr;
		size = 0;
		return;
	}
	myNode<T>* newfirst = chain.firstNode;
	newfirst = new myNode<T>(firstNode->element, firstNode->next);
	newfirst = newfirst->next;
	myNode<T>* temp = firstNode;
	while (newfirst != nullptr) {
		temp->next = newfirst;
		newfirst = newfirst->next;
		temp = temp->next;
	}
	temp->next = nullptr;
	lastNode = temp;
}

template<typename T>
myExtendedChainList<T>::~myExtendedLChainList()
{
	 while (firstNode != nullptr) {
		 myChainNode<T>* temp = firstNode->next;
		 delete firstNode;
		 firstNode = temp;
}
